package com.woniuxy.stage3demo.controller.gy;

import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.gy.OverdueIm;
import com.woniuxy.stage3demo.bean.gy.PrRepaymentInfoBean;
import com.woniuxy.stage3demo.bean.gy.UserDemo;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.pageHelper.TableResult;
import com.woniuxy.stage3demo.service.gy.OverduePrRepaymentInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：苟杨
 * @description：TODO
 * @date ：2020/12/15 16:00
 */
@RequestMapping("/pc")
@RestController
public class PrepaymentController {
    @Resource
    private OverduePrRepaymentInfoService overduePrRepaymentInfoService;

    //查询
    @GetMapping(value = "/page",produces = {"application/json;charset=utf-8"})
    public TableResult findPage(PageRequest pageRequest, UserDemo userDemo){
        PageInfo<PrRepaymentInfoBean> all = overduePrRepaymentInfoService.findAll(pageRequest.getPageNum(), pageRequest.getLimit(), userDemo);
        System.out.println(all+"aaa");
        long total = all.getTotal();
        List<PrRepaymentInfoBean> rows = all.getList();
        TableResult tr = new TableResult<>();
        tr.setTotal(total);
        tr.setRows(rows);
        return tr;
    }
    //查询人数、金额
    @GetMapping(value = "/pre",produces = {"application/json;charset=utf-8"})
    public OverdueIm findAll(){
        int countMonth = overduePrRepaymentInfoService.findCountMonth();
        int countYear = overduePrRepaymentInfoService.findCountYear();
        List<Integer> moneyMonth = overduePrRepaymentInfoService.findMoneyMonth();
        long[] countNum1 = {0};
        moneyMonth.forEach(e->{
            countNum1[0] = countNum1[0] +e;
        });
        List<Integer> moneyYear = overduePrRepaymentInfoService.findMoneyYear();
        long[] countNum2 = {0};
        moneyYear.forEach(e->{
            countNum2[0] = countNum2[0] +e;
        });
        OverdueIm oi = new OverdueIm();
        oi.setCountMonth(countMonth);
        oi.setCountYear(countYear);
        oi.setCountMonthCount(countNum1[0]);
        oi.setCountYearCount(countNum2[0]);
        return oi;
    }
}
